<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最终继承的方案写法</title>
</head>
<body>
  
  <script>

     // 寄生组合式继承
    // 原型链/借用/原型式(对象之间)/寄生式函数
    function Person(name, age, height) {
      this.name = name
      this.age = age
      this.height = height
    }

    Person.prototype.running = function() {
      console.log("running~")
    }
    Person.prototype.eating = function() {
      console.log("eating~")
    }


    function Student(name, age, height, sno, score) {
      Person.call(this, name, age, height)
      this.sno = sno
      this.score = score
    }
    
    inherit(Student, Person)

    Student.prototype.studying = function() {
      console.log("studying")
    }

     // 创建实例对象
     var stu1 = new Student("why", 18, 1.88, 111, 100)

    //继承对象的方法
    function createObject(o) {
      function F() {}
      F.prototype = o
      return new F()
    }

    function inherit(Substye, Supertype) {
      
      Substye.prototype = createObject(Supertype)
      Object.defineProperty(Substye.prototype, "constructor", {
        enumerable: false,
        configurable: true,
        writable: true,
        value: Substye
      })
      Object.setPrototypeOf(Substye, Supertype)
    }
  </script>
</body>
</html>